﻿using System;
using System.Linq;
using System.Linq.Expressions;
using EntityFramework.Database.Management;

namespace Sample.Application
{
    public abstract class Repository<T> where T : class
    {
        private static IObjectContextProvider _contextProvider;

        protected Repository(IObjectContextProvider contextProvider)
        {
            _contextProvider = contextProvider;
        }

        public T Find(Expression<Func<T, bool>> predicate)
        {
            return _contextProvider.GetContext<MyContext>().GetIQueryable<T>().Where(predicate).SingleOrDefault();
        }
    }
}